package ua.eug.robov2.schematic.chips;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import ua.eug.robov2.schematic.SheetMap;
import ua.eug.robov2.utils.Vector2i;

public abstract class Chip implements Externalizable{
	Pin[] pins;
	protected Vector2i[] pinPos;
	protected SheetMap chipMap; // mini-map of chip
	protected String name;
	public int chipIndex;
	
	public Chip () {

	}
	
	public void setIndex(int index) {
		chipIndex = index;
		for (Pin p : pins) {
			p.chip = index;
		}
	}
	
	// prepare all necessary functions
	public abstract void act();

	public void fillMap() {
		
	}
	
	@Override
	public void readExternal(ObjectInput oin) throws IOException,
			ClassNotFoundException {
		chipIndex = oin.readInt();
		name= (String) oin.readObject();	
	}

	@Override
	public void writeExternal(ObjectOutput oout) throws IOException {
		oout.writeInt(chipIndex);
		oout.writeObject(name);
	}

}
